package com.awesome.lifecycledemo.livedata;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;

import android.os.Bundle;

import com.awesome.lifecycledemo.R;
import com.awesome.sdk.util.ShowLogUtil;

public class MultiActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_multi);
        MutableLiveData<String> mutableLiveData1=new MutableLiveData<>();
        MutableLiveData<String> mutableLiveData2=new MutableLiveData<>();
        MediatorLiveData liveDataMeger = new MediatorLiveData<String>();
        liveDataMeger.addSource(mutableLiveData1, new Observer() {
            @Override
            public void onChanged(Object o) {
                ShowLogUtil.info("change1:"+o.toString());
            }
        });
        liveDataMeger.addSource(mutableLiveData2, new Observer() {
            @Override
            public void onChanged(Object o) {
                ShowLogUtil.info("change2:"+o.toString());
            }
        });
        liveDataMeger.observe(this, new Observer() {
            @Override
            public void onChanged(Object o) {
                ShowLogUtil.info("changed:"+o.toString());
            }
        });
        mutableLiveData1.postValue("how are you");
    }
}